package com.sinothk.hussars.controller;


import com.sinothk.hussars.base.entity.PageReq;
import com.sinothk.hussars.entity.*;
import com.sinothk.hussars.service.OrgCheckService;
import com.sinothk.hussars.utils.XUtils;
import com.sinothk.server.support.annotation.callback.BizException;
import com.sinothk.server.support.annotation.callback.ResponseResult;
import com.sinothk.server.support.entity.PageData;
import com.sinothk.server.support.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.sinothk.hussars.base.BaseController;

import java.util.Date;

/**
 * <p>
 * 采集机构表 前端控制器
 * </p>
 *
 * @author liangyt
 * @since 2021-01-05
 */
@Api(tags = "机构_检测机构")
@RestController
@RequestMapping("/orgCheck")
@ResponseResult()
public class OrgCheckController extends BaseController {

    private final OrgCheckService orgCheckService;

    public OrgCheckController(OrgCheckService orgCheckService) {
        this.orgCheckService = orgCheckService;
    }

    @ApiOperation(value = "新增：检测机构")
    @PostMapping("/save")
    public OrgCheckEntity save(@RequestBody OrgAddVo workerCheckerVo) {
        // 参数验证
        if (StringUtil.isEmpty(workerCheckerVo.getOrgName())) throw new BizException("机构名称不能为空");
        if (StringUtil.isEmpty(workerCheckerVo.getManagerAccount())) throw new BizException("管理员账号不能为空");
        if (StringUtil.isEmpty(workerCheckerVo.getManagerPwd())) throw new BizException("管理员密码不能为空");

        return orgCheckService.add(workerCheckerVo);
    }

    @ApiOperation(value = "查询：检测机构分页列表")
    @PostMapping("/orgPage")
    public PageData orgPage(@RequestBody PageReq<OrgCheckEntity> pageVo) {
        // 参数验证
        if (pageVo.getPageSize() == 0) pageVo.setPageSize(20);
        return orgCheckService.orgPage(pageVo);
    }

    @ApiOperation(value = "更新：检测机构")
    @PostMapping("/update")
    public OrgCheckEntity update(@RequestBody OrgEditVo orgVo) {
        // 参数验证
        if (StringUtil.isEmpty(orgVo.getId())) throw new BizException("部门Id不能为空");
        return orgCheckService.edit(orgVo);
    }
}

